package path;

import geom.*;

public class KeyFrame implements Comparable{
	private long time;
	private long length;
	private Vector position;
	private AxisAngle orientation;
	private float visibility;
	boolean original;
	
	public KeyFrame(Vector pos, AxisAngle orient, long f, float vis, long length, boolean orig) {
		setPosition(pos);
		setOrientation(orient);
		setTime(f);
		visibility = vis;
		this.length = length;
		original = orig;
	}
	
	public KeyFrame(Vector pos, AxisAngle orient, long f, float vis) {
		this(pos, orient, f, vis, 0, true);
	}
	
	public KeyFrame(Vector pos, AxisAngle orient, long f) {
		this(pos, orient, f, 1);
	}
	
	public KeyFrame(Vector pos, long f){
		this(pos, null, f);
	}
	
	public KeyFrame(AxisAngle orient, long f){
		this(null, orient, f);
	}
	
	public KeyFrame(Vector pos, long f, float vis){
		this(pos, null, f, vis);
	}
	
	public KeyFrame(AxisAngle orient, long f, float vis){
		this(null, orient, f, vis);
	}
	
	public KeyFrame(){
		this(null, null, 0, 1);
	}
	
	public long getTime() {
		return time;
	}

	public AxisAngle getOrientation() {
		return orientation;
	}

	public Vector getPosition() {
		return position;
	}

	public void setTime(long frame) {
		this.time = frame;
	}

	public void setOrientation(AxisAngle orientation) {
		this.orientation = orientation;
	}

	public void setPosition(Vector position) {
		this.position = position;
	}
	
	public float getVisibility() {
		return visibility;
	}

	public void setVisibility(float visibility) {
		this.visibility = visibility;
	}
	
	public boolean isEqualTo(KeyFrame kf){
		if(time != kf.getTime()) return false;
		if(length != kf.getLength()) return false;
		if(visibility != kf.getVisibility()) return false;
		if(original != kf.original) return false;
		if(!position.equalTo(kf.getPosition())) return false;
		
		/*
		
		if(orientation == null){
			if(kf.getOrientation() != null) return false;
		} else {
			if(kf.getOrientation() != null) return false;
			if(!orientation.equalTo(kf.getOrientation())) return false;
		}
		*/
		return true;
	}

	public int compareTo(Object o) throws ClassCastException{
		if(!(o instanceof KeyFrame)) throw new ClassCastException();
		KeyFrame kf = (KeyFrame)o;
		if(time > kf.getTime()) return 1;
		if(time < kf.getTime()) return -1;
		return 0;
	}
	
	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append("KeyFrame: { ");
		sb.append("Frame: ");
		sb.append(time);
		if(position != null){
			sb.append("Position: ");
			sb.append(position.toString());
		}
		if(orientation != null){
			sb.append(" Orientation: ");
			sb.append(orientation.toString());
		}
		sb.append(" Visibility: ");
		sb.append(visibility);
		sb.append("original ");
		sb.append(original);
		sb.append(" }");
		return sb.toString();
	}

	public long getLength() {
		return length;
	}

	public void setLength(long length) {
		this.length = length;
	}

	public KeyFrame getCopy(){
		Vector position = null;
		if(this.position != null)
			position = this.position.getCopy();
		AxisAngle orientation = null;
		if(this.orientation != null)
			orientation = orientation.getCopy();
		return new KeyFrame(position, orientation, time, visibility, length, original);
	}


}
